﻿using System;
using System.Configuration;

namespace SharedGenomics.Core.Configuration
{
    public class InstanceConfigurationReader : ConfigurationReaderBase
    {
        private readonly AppSettingsSection _appSettings;
        private readonly ConnectionStringsSection _connectionStrings;

        public InstanceConfigurationReader(AppSettingsSection appSettings, ConnectionStringsSection connectionStrings)
        {
            appSettings.ThrowIfNull("appSettings");
            connectionStrings.ThrowIfNull("connectionStrings");

            this._appSettings = appSettings;
            this._connectionStrings = connectionStrings;
        }

        public override string GetConnectionString(string connectionStringName)
        {
            connectionStringName.ThrowIfNull("connectionStringName");

            var connString = this._connectionStrings.ConnectionStrings[connectionStringName];
            return connString == null ? null : connString.ConnectionString;
        }

        public override string GetAppSetting(string settingName)
        {
            settingName.ThrowIfNull("settingName");
            var setting = this._appSettings.Settings[settingName];

            return setting == null ? null : setting.Value;
        }
    }
}
